const express = require('express')

const {
	addProject,
	listProject,
	updateProject,
	listTeam,
	lockProject,
	unlockProject,
	projectVersionList,
} = require('../modules/module-project')

const router = express.Router()

// /ult/project/list
router.post('/project/list', function(req, res, next) {
	let {
		user_id,
		user_role,
	} = req.body
	listProject(user_id, user_role).then(result => {
		res.type('json').send(result)
	})
})

// /ult/project/edit
router.post('/project/edit', function(req, res, next) {
	let params = req.body
	if (params.flag == 'add') {
		return addProject(params).then(result => {
			res.type('json').send(result)
		})
	}
	return updateProject(params).then(result => {
		res.type('json').send(result)
	})
})

// /ult/project/locked
router.get('/project/locked', function(req, res, next) {
	let {
		project_id,
		locked_user,
	} = req.query
	return lockProject(project_id, locked_user).then(result => {
		res.type('json').send(result)
	})
})

// /ult/project/unlock
router.get('/project/unlock', function(req, res, next) {
	let {
		project_id,
	} = req.query
	return unlockProject(project_id).then(result => {
		res.type('json').send(result)
	})
})

// /ult/project/version
router.post('/project/version', function(req, res, next) {
	return projectVersionList(req.body).then(result => {
		res.type('json').send(result)
	})
})

module.exports = router